package com.mystore.service.impl;

import com.mystore.dao.AddressDao;
import com.mystore.dao.impl.AddressDaoImpl;
import com.mystore.entity.Address;
import com.mystore.service.AddressService;
import com.mystore.util.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class AddressServiceImpl implements AddressService {

    @Override
    public List<Address> findAllMyAddressByUid(int uid) {
        Connection connection = DBUtil.getConntion();
        AddressDao addressDao = new AddressDaoImpl();
        List<Address> list = addressDao.findAllMyAddressByUid(uid,connection);
        DBUtil.closeConnection(connection);
        return list;
    }

    @Override
    public Address findAddressByAidAndUid(int id, int uid) {
        Connection connection = DBUtil.getConntion();
        AddressDao addressDao = new AddressDaoImpl();
        Address address = addressDao.findAddressByAidAndUid(id,uid,connection);
        DBUtil.closeConnection(connection);
        return address;
    }

    @Override
    public Boolean save(Address address) throws SQLException {
        Connection connection = DBUtil.getConntion();
        AddressDao addressDao = new AddressDaoImpl();
        Boolean isAdd = addressDao.save(address,connection);
        DBUtil.closeConnection(connection);
        return isAdd;
    }
}
